import type { GlobalThemeOverrides } from 'naive-ui';
import naiveUiTheme from './naive-ui-theme-overrides.json';

const peersTheme: GlobalThemeOverrides = {
	DataTable: {
		peers: {
			Pagination: {},
		},
	},
	Ellipsis: {
		peers: {
			Tooltip: {
				peers: {
					Popover: {
						padding: '4px 10px',
					},
				},
			},
		},
	},
	Select: {
		peers: {
			InternalSelection: {
				heightMedium: naiveUiTheme.Input.heightMedium,
				placeholderColor: naiveUiTheme.Input.placeholderColor,
				placeholderColorDisabled: naiveUiTheme.Input.placeholderColorDisabled,
				colorActive: naiveUiTheme.Input.colorFocus,
				colorDisabled: naiveUiTheme.Input.colorDisabled,
				color: naiveUiTheme.Input.color,
				fontSizeMedium: naiveUiTheme.Input.fontSizeMedium,
			},
			InternalSelectMenu: {
				color: '#525B74',
				optionColorPending: '#485066',
				optionColorActivePending: '#485066',
			},
		},
	},
	TreeSelect: {
		peers: {
			InternalSelection: {
				heightMedium: naiveUiTheme.Input.heightMedium,
				placeholderColor: naiveUiTheme.Input.placeholderColor,
				placeholderColorDisabled: naiveUiTheme.Input.placeholderColorDisabled,
				colorActive: naiveUiTheme.Input.colorFocus,
				colorDisabled: naiveUiTheme.Input.colorDisabled,
				color: naiveUiTheme.Input.color,
				fontSizeMedium: naiveUiTheme.Input.fontSizeMedium,
			},
			Tree: {
				nodeColorHover: '#485066',
			},
		},
	},
	Dialog: {
		peers: {
			Button: {
				fontSizeSmall: '12px',
			},
		},
	},
	AutoComplete: {
		peers: {
			InternalSelectMenu: {
				color: '#525B74',
				optionColorPending: '#485066',
				optionColorActivePending: '#485066',
			},
		},
	},
};

// 合并peersTheme和naiveUiTheme
const themeKeyArr: string[] = [];
for (const key in naiveUiTheme) {
	themeKeyArr.push(key);
}
for (const peerkey in peersTheme) {
	if (themeKeyArr.includes(peerkey)) {
		for (const key in naiveUiTheme) {
			if (key === peerkey) {
				naiveUiTheme[key].peers = peersTheme[peerkey].peers;
			}
		}
	} else {
		naiveUiTheme[peerkey] = peersTheme[peerkey];
	}
}

export const themeOverrides: GlobalThemeOverrides = naiveUiTheme;
// export const themeOverrides: GlobalThemeOverrides = {};
